home *** CD-ROM | disk | FTP | other *** search
- unit KeysU2;
-
- interface
-
- procedure PressKey(Key: Char);
- procedure ReleaseKey(Key: Char);
- procedure SendKeys(const Keys: String);
-
- const
- SnapShotWholeScreen: Boolean = False;
-
- implementation
-
- uses
- Windows, Forms;
-
- procedure PostVirtualKeyEvent(vk: Word; fUp: Boolean);
- var
- ScanCode: Byte;
- Input: TInput;
- const
- KeyEventF_KeyDown = 0;
- //This constant is defined incorrectly in Delphi 4
- Input_KeyBoard = 1;
- ButtonUp: array[Boolean] of Byte = (KeyEventF_KeyDown, KeyEventF_KeyUp);
- begin
- if vk = vk_SnapShot then
- { Special processing for the PrintScreen key. }
- { If scan code is set to 1 it copies entire }
- { screen. If set to 0 it copies active window. }
- ScanCode := Byte(SnapShotWholeScreen)
- else
- ScanCode := MapVirtualKey(vk, 0);
- FillChar(Input, SizeOf(Input), 0);
- Input.IType := Input_KeyBoard;
- Input.KI.wVk := vk;
- Input.KI.wScan := ScanCode;
- Input.KI.dwFlags := ButtonUp[fUp];
- Input.KI.time := GetTickCount;
- SendInput(1, Input, SizeOf(Input))
- end;
-
- procedure PressKey(Key: Char);
- begin
- PostVirtualKeyEvent(Ord(Key), False)
- end;
-
- procedure ReleaseKey(Key: Char);
- begin
- PostVirtualKeyEvent(Ord(Key), True)
- end;
-
- procedure SendKeys(const Keys: String);
- var
- Loop: Byte;
- begin
- for Loop := 1 to Length(Keys) do
- begin
- PostVirtualKeyEvent(Ord(Keys[Loop]), False); { Press key }
- PostVirtualKeyEvent(Ord(Keys[Loop]), True); { Release key }
- end;
- { Let the keys be processed }
- Application.ProcessMessages;
- end;
-
- end.
-